/*
 * Copyright 2012 Gregor Schauer
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package at.schauer.gregor.vienna.example.common.entity;

import javax.persistence.*;
import java.util.Set;
import java.util.UUID;

/**
 * @author Gregor Schauer
 */
@Entity
public class Customer extends Person {
	private Set<Address> addresses;

	private UUID session;

	public Customer() {
	}

	public Customer(Long id, String name, Set<Address> addresses, UUID session) {
		this.id = id;
		this.name = name;
		this.addresses = addresses;
		this.session = session;
	}

	@Id
	@GeneratedValue
	@Column(name = "pk")
	@Override
	public Long getId() {
		return id;
	}

	@OneToMany(mappedBy = "customer", fetch = FetchType.EAGER)
	public Set<Address> getAddresses() {
		return addresses;
	}

	public void setAddresses(Set<Address> addresses) {
		this.addresses = addresses;
	}

	@Transient
	public UUID getSession() {
		return session;
	}

	public void setSession(UUID session) {
		this.session = session;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof Customer)) {
			return false;
		}

		Customer customer = (Customer) obj;

		if (getId() != null ? !getId().equals(customer.getId()) : customer.getId() != null) {
			return false;
		}

		return true;
	}

	@Override
	public int hashCode() {
		return getId() != null ? getId().hashCode() : 0;
	}
}
